package com.czj.controller;

import com.czj.common.api.CommonResult;
import com.czj.model.Find;
import com.czj.service.FindService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "FindController", description = "发现模块")
@RequestMapping("/find")
public class FindController {

    @Autowired
    private FindService findService;

    /**
     * 分页查询全部发现
     * @param pageSize
     * @param pageNum
     * @return
     */
    @ApiOperation(value = "分页查询全部发现")
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public CommonResult<List<Find>> list(@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                   @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {

        List<Find> findList = findService.list(pageSize,pageNum);
        return CommonResult.success(findList);
    }


    @ApiOperation("获取单个发现详情信息")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public CommonResult getItem(@PathVariable Integer id) {
        //查询
        Find find = findService.getItem(id);
        int count = find.getCount();
        find.setCount(++count);
        boolean result = findService.updateConut(find);
        return CommonResult.success(find);

    }

}
